package it.traveldreamWeb.shared;

import it.traveldream.dto.HotelDTO;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

public class HotelDataModel extends ListDataModel<HotelDTO> implements SelectableDataModel<HotelDTO>{
	public HotelDataModel() {  
    }  
  
    public HotelDataModel(List<HotelDTO> data) {  
        super(data);  
    }

	@Override
	public HotelDTO getRowData(String rowKey) {
		
		@SuppressWarnings("unchecked")
		List<HotelDTO> hotels = (List<HotelDTO>) this.getWrappedData();
		
		for (HotelDTO h : hotels){
			if (h.getProductId().equals(Long.decode(rowKey)))
				return h;
		}
		return null;
	}

	@Override
	public Object getRowKey(HotelDTO h) {
		return h.getProductId();
	} 
}
